import axios from 'axios'
// import { removetoken } from './storage'
import store from '../store'
import router from '../router'
import { Toast } from 'vant';

const request = axios.create({
  baseURL: 'http://124.223.14.236:8060/home/',
 
})
// 请求拦截器
request.interceptors.request.use(config => {
  // Do something before request is sent
  // console.log(config);
  if (store.state.Login.token) {
    config.headers['Token'] = store.state.Login.token
  }
  return config;
}, error => {
  // Do something with request error
  return Promise.reject(error);
});
// 响应拦截器
request.interceptors.response.use(response => {
  // Do something before response is sent
  // console.log(response.data);
  if (response.data.errno === 9997 || response.data.errno === 9998) {
    Toast.fail(response.data.errmsg)
    store.commit('Login/deltoken')
    router.push('/login')
  } 
  return response.data;
}, error => {
  // console.log(error.response);
  // Do something with response error
  return Promise.reject(error);
});
export default request